﻿// --------------------------------
// <copyright file="IntrinsicElementCollection.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using System.Configuration;

namespace Tronsoft.Actucal.CalculationEngineCreator.ScriptConfiguration
{
    /// <summary>
    /// This class represents a collection of script elements in the application's configuration file. see the example. It inherits
    /// from the <see cref="ConfigurationElementCollection"/> class.
    /// 
    /// Example:
    ///   <scriptGeneration>
    ///     <IntrinsicObject name="test1" sourceDirectory="c:\temp\input" processedDirectory="c:\temp\processed">
    ///         <scripts>
    ///             <clear/>
    ///             <add name="testScript1.txt" outputDirectory="c:\temp\output" template="c:\temp\script\template1.txt"  type="Tronsoft.Actucal.CalculationEngineCreator.FileNameReplacerProcessor, Tronsoft.Actucal.CalculationEngineCreator" />
    ///             <add name="testScript2.txt" outputDirectory="c:\temp\output" template="c:\temp\script\template2.txt" type="Tronsoft.Actucal.CalculationEngineCreator.FileNameReplacerProcessor, Tronsoft.Actucal.CalculationEngineCreator" />
    ///         </scripts>
    ///     </IntrinsicObject>
    ///    </scriptGeneration>
    /// 
    /// </summary>
    [ConfigurationCollection(typeof(IntrinsicElement), AddItemName = ConfigurationPropertyName.INTRINSIC_OBJECT_ELEMENT)]
    public class IntrinsicElementCollection : ConfigurationElementCollection
    {
        public IntrinsicElementCollection()
            : base(StringComparer.OrdinalIgnoreCase)
        {
        }

        public IntrinsicElement this[int index]
        {
            get { return (IntrinsicElement) base.BaseGet(index); }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        public new IntrinsicElement this[string key]
        {
            get { return (IntrinsicElement) base.BaseGet(key); }
        }

        public void Add(IntrinsicElement item)
        {
            if (item != null)
            {
                BaseAdd(item);
            }
        }

        public void Clear()
        {
            base.BaseClear();
        }


        protected override ConfigurationElement CreateNewElement()
        {
            return new IntrinsicElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((IntrinsicElement) element).Name;
        }

        public void Remove(string name)
        {
            base.BaseRemove(name);
        }

        // Properties
    }
}